package everyday.apr;

/**
 * 762. 二进制表示中质数个计算置位
 */
public class Day5 {
    public static void main(String[] args) {
        System.out.println(countPrimeSetBits(6, 10));
        System.out.println(countPrimeSetBits(10, 15));
    }

    /**
     * bitCount方法位1计数，判断是否位质数：32以内的质数是有限的
     */
    public static int countPrimeSetBits(int left, int right) {
        int ans = 0;
        for (int i = left; i <= right; ++i) {
            int pos = Integer.bitCount(i);
            if (pos == 2 || pos == 3 || pos == 5 || pos == 7 || pos == 11 || pos == 13 || pos == 17 || pos == 19) ans++;
        }
        return ans;
    }
}
